#include "FPCH.h"

#include "FTextEncoding.h"

namespace Font
{

	TextEncoding::TextEncoding(Library* a_Library)
	{
		m_Library = a_Library;
	}
	
	TextEncoding::~TextEncoding()
	{
		
	}

	TextInstructions* TextEncoding::ParseFromUtf16(const unsigned char* a_Message)
	{
		TextInstructions* result = new TextInstructions(m_Library);

		// TODO: Fix newline issue?

		bool newline = false;
		const wchar_t* src_prev = NULL;
		const wchar_t* src = (const wchar_t*)a_Message;
		while (*src)
		{
			if (newline)
			{
				result->AddCommand(Instruction::eNewLine);
				newline = false;
			}

			if (*src == L'\r' || *src == L'\n')
			{
				newline = true;
			}
			else if (*src == L'\t')
			{
				result->AddCommand(Instruction::eTab);
			}

			result->AddCommand(Instruction::eCharacter, (unsigned int)*src);

			src_prev = src;
			src++;
		}

		return result;
	}

}; // namespace Font